package com.github.chirspan.xaas.uc.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.chirspan.xaas.uc.dao.OrgDepartmentDao;
import com.github.chirspan.xaas.uc.model.OrgDepartment;
import com.github.chirspan.xaas.bo.DepartmentBO;
import com.github.chirspan.xaas.mybatis.service.impl.BaseServiceImpl;
import com.github.chirspan.xaas.mybatis.util.tree.TreeUtils;
import com.github.chirspan.xaas.uc.service.IOrgDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: chenpan
 * @Date: 2021-08-10 11:03:10
 * @Description: 科室信息 接口实现
 */
@Service
public class OrgDepartmentServiceImpl extends BaseServiceImpl<OrgDepartmentDao, OrgDepartment> implements IOrgDepartmentService {

    @Autowired
    private OrgDepartmentDao departmentDao;

    @Override
    public List<OrgDepartment> getDepTree(OrgDepartment department) {
        List<OrgDepartment> departments = departmentDao.selectList(Wrappers.query(department));
        return TreeUtils.buildTree(departments);
    }

    @Override
    @Cacheable(value = "uc:user-dept", key = "#p0", unless = "#result == null || #result.size() == 0")
    public List<DepartmentBO> getDepartmentByUsername(String username) {
        return departmentDao.selectDepartmentByUsername(username);
    }
}
